﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace RubikSolve {
    class Button {
        public Texture2D img;
        public Vector2 position = new Vector2();
        private ButtonState previous, current;

        public Button(Texture2D image) {
            img = image;
            previous = ButtonState.Released;
        }

        /// <summary>
        /// Check whether the given Vector2 is inside the region or outside
        /// </summary>
        public bool insideRegion(MouseState mouse) {
            if (mouse.X >= position.X && mouse.X <= position.X + img.Width && mouse.Y >= position.Y && mouse.Y <= position.Y + img.Height) {
                return true;
            }
            else return false;
        }

        /// <summary>
        /// Check whether the button is clicked or not
        /// </summary>
        public bool click() {
            bool ret = false;
            current = Mouse.GetState().LeftButton;
            if (current == ButtonState.Pressed && insideRegion(Mouse.GetState()) && previous == ButtonState.Released) {
                ret = true;
            }
            previous = current;
            return ret;
        }

        public void setPosition(Vector2 pos) {
            this.position = pos;
        }
    }
}